package com.school.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.school.pojo.Account;
import com.school.pojo.Inform;
import com.school.service.InformService;
import com.school.util.Result;
import com.school.util.Tool;

@RequestMapping("/inform")
@RestController
public class InformController implements Tool<Inform>{

	@Autowired
	private InformService informService;

	@Override
	@RequestMapping("/findAll")
	public Result<Inform> findAll(int page, int pageSize, Inform t) {
		
		List<Inform> informs= informService.findAll(page,pageSize,t);
		PageInfo<Inform> info=new PageInfo<Inform>(informs);
		Result<Inform> result=new Result<Inform>();
		result.setList(info.getList());
		result.setCount(info.getTotal());
		return result;
	}

	@Override
	@RequestMapping("/findById")
	public Result<Inform> findbyId(int id) {
		
		return null;
	}

	@Override
	public int add(Inform t) {
		
		return 0;
	}

	@Override
	public int edit(Inform t) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int del(int id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	@RequestMapping("/delbatch")
	public int delbatch(int[] id) {
		
		return informService.delbatch(id);
	}
	
	@RequestMapping("/adds")
	public int adds(Inform t,HttpServletRequest request,HttpServletResponse response) {
		Account o= (Account)request.getSession().getAttribute("account");
		
		if(o==null) {
			return 0;
		}
		t.setTeacher_id(o.getAccount_id());
		int row=informService.adds(t);
		return row;
	}
	
	
}
